<?php

namespace App\Notifications;

use App\Models\Topic;
use App\Models\User;
use Encore\Admin\Auth\Database\Administrator;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class TopicRestored extends Notification
{
    use Queueable;

    private $topic;

    private $operator;

    /**
     * Create a new notification instance.
     *
     * @param Topic $topic
     * @param Administrator $operator
     */
    public function __construct(Topic $topic, User $operator)
    {
        $this->topic = $topic;

        $this->operator = $operator;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['database'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            'user_id' => $this->operator->id,
            'username' => $this->operator->username,
            'user_avatar' => $this->operator->avatar,
            'target_id' => $this->topic->id,
            'target_title' => $this->topic->titleExcerpt,
            'action_id' => 0,
            'action_title' => '',
        ];
    }
}
